package com.whz.governance.http.client;

import com.alibaba.cloud.sentinel.custom.SentinelProtectInterceptor;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpResponse;

/**
 * @author whz
 * @see SentinelProtectInterceptor
 */
public interface CommonFeignFallBackProvider {

    /**
     * feign client的通用服务降级处理器
     *
     * @param request   请求
     * @param body      请求体
     * @param execution 请求执行上下文
     * @param ex        异常
     * @return response
     */
    ClientHttpResponse fallBackHandler(HttpRequest request, byte[] body,
                                       ClientHttpRequestExecution execution, BlockException ex);


    /**
     * 限流通用处理器
     *
     * @param request   请求
     * @param body      请求体
     * @param execution 请求执行上下文
     * @param ex        异常
     * @return response
     */
    ClientHttpResponse blockHandler(HttpRequest request, byte[] body,
                                    ClientHttpRequestExecution execution, BlockException ex);
}